
package card;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;

/**
 *
 * @author DA5221-GRP63
 */

public class eventFrame extends JFrame implements TreeSelectionListener{
  BorderLayout borderLayout1 = new BorderLayout();
  JSplitPane jSplitPane1 = new JSplitPane();
  JScrollPane jScrollPane1 = new JScrollPane();
  JTree jTree1;
  public eventFrame()
  {
    try
    {
      Toolkit kit = Toolkit.getDefaultToolkit();
      Image img=kit.getImage("img/img.gif");
      this.setIconImage(img);
      Dimension screenSize=kit.getScreenSize();
      Dimension size=new Dimension(520,360);
      this.setSize(size);
      setLocation((screenSize.width-size.width)/2,(screenSize.height-size.height)/2);
      jbInit();
    } catch( Exception exception )
    {
      exception.printStackTrace();
    }
  }

  private void jbInit() throws Exception
  {
    getContentPane().setLayout( borderLayout1 );
    this.setTitle( "The Management System Of Credit Card" );
    this.getContentPane().add( jSplitPane1, java.awt.BorderLayout.CENTER );
    //JTree１model
    DefaultMutableTreeNode root=new DefaultMutableTreeNode("Credit Card System");
    DefaultMutableTreeNode bitchThing=new DefaultMutableTreeNode("Info");
    root.add(bitchThing);//add bitchThing
    bitchThing=new DefaultMutableTreeNode("Deposit Money");
    root.add(bitchThing);
    bitchThing=new DefaultMutableTreeNode("WithDraw Money");
    root.add(bitchThing);
    jTree1=new JTree(root);

    jSplitPane1.add( jScrollPane1, JSplitPane.LEFT );
    jSplitPane1.add(new welcomePanel(),JSplitPane.RIGHT);
    jScrollPane1.getViewport().add( jTree1 );
    jSplitPane1.setDividerLocation( 130 );

    jTree1.addTreeSelectionListener(this);
    int mode=TreeSelectionModel.SINGLE_TREE_SELECTION;
    jTree1.getSelectionModel().setSelectionMode(mode);//choose the modle
  }
  public void valueChanged(TreeSelectionEvent event){
    String node=jTree1.getLastSelectedPathComponent().toString();//get the choose

    if(node.equals("Info"))
    {
      jSplitPane1.remove(jSplitPane1.getRightComponent());//go to the right page
      jSplitPane1.setDividerLocation( 130 );
      jSplitPane1.add(new queryPanel(CardID),JSplitPane.RIGHT);
    }else if(node.equals("Deposit Money"))
    {
      jSplitPane1.remove(jSplitPane1.getRightComponent());//go to the right page
      jSplitPane1.setDividerLocation( 130 );
      jSplitPane1.add(new storePanel(CardID,this),JSplitPane.RIGHT);
    }else if(node.equals("WithDraw Money"))
    {
      jSplitPane1.remove(jSplitPane1.getRightComponent());//go ro the right page
      jSplitPane1.setDividerLocation( 130 );
      jSplitPane1.add(new getPanel(CardID,this),JSplitPane.RIGHT);
    }else if(node.equals("Credit Card System"))
    {
      jSplitPane1.remove(jSplitPane1.getRightComponent());//go to the right page
      jSplitPane1.setDividerLocation( 130 );
      jSplitPane1.add(new welcomePanel(),JSplitPane.RIGHT);
    }
  }
  public void setQueryState()
  {
    jSplitPane1.remove(jSplitPane1.getRightComponent());//go to the right page
    jSplitPane1.setDividerLocation( 130 );
    jSplitPane1.add(new queryPanel(CardID),JSplitPane.RIGHT);
  }
  public void setCardID(String id)
  {
    this.CardID=id;
  }
  public void setUserName(String un)
  {
    this.userName=un;
  }
  public String getUserName()
  {
    return userName;
  }
  String userName;
  String CardID=null;
}

